#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/12/6 8:45
# @Author  : FuKai ZHANG
# @File    : models.py
# @Description :这里规范的定义一些数据检查和交换的接口
from pydantic import BaseModel
from typing import Union, Text, Dict, Any, Optional
from enum import Enum
from dataclasses import dataclass

"""system config 相关"""


class MySqlDB(BaseModel):
    """msql"""
    host: Union[Text, None] = None
    db:Union[Text, None] = None
    user: Union[Text, None] = None
    password: Union[Text, None] = None
    port: Union[int, None] = 3306


# REDIS
class Redis(BaseModel):
    """redis"""
    host: Union[Text, None] = None
    password: Union[Text, None] = None
    port: Union[int, None] = 6379
    db: Union[Text, None] = 0


# EMAIL
class Email(BaseModel):
    """邮件通知"""
    send_user: Union[Text, None]
    email_host: Union[Text, None]
    stamp_key: Union[Text, None]
    # 收件人
    send_list: Union[Text, None]

class Dingtalk(BaseModel):
    """钉钉通知"""
    webhook: Union[Text, None]


# SYSTEM CONFIG
class Config(BaseModel):
    """系统配置"""
    project_name: Text
    project_version: Text
    tester_name: Text
    host: Union[Text, None]
    mysql_db: "MySqlDB"
    email: "Email"
    redis_db: "Redis"
    dingtalk: "Dingtalk"
    Multi_threaded_load:bool
    Pytest_xdis: bool


"""case 枚举相关 用来校验输入的用例是否符合模板"""


class RequestType(Enum):
    """
    request请求发送，请求参数的数据类型,用来校验REQUEST_TYPE字段值
    """
    JSON = "JSON"
    PARAMS = "PARAMS"
    FORM = "FORM"
    FILE = "FILE"
    EXPORT = "EXPORT"  # 无参数请求类型，如导出接口



class TestCaseEnum(Enum):
    """用例模板，用来校验单个用例是否字段完整"""
    URL = "url"
    METHOD = "method"
    DETAIL = "detail"
    HEADERS = "headers"
    REQUEST_TYPE = "requestType"
    DATA = "data"
    EXPECTED = "expected"
    EXTRACT = "extract"


class Method(Enum):
    """请求方式，用来校验用例的METHOD字段"""
    GET = "GET"
    POST = "POST"
    PUT = "PUT"
    PATCH = "PATCH"
    DELETE = "DELETE"
    HEAD = "HEAD"
    OPTION = "OPTION"


"""case models相关"""


class TestCase(BaseModel):
    url: Text
    method: Text
    detail: Text
    headers: Union[None, Dict]
    requestType: Text
    data: Any = Union[None, Dict]
    expected: Union[None, Dict]
    extract: Union[None, Dict]


# 这里根据需要对应requests_control里的 check_case_complete_params()再做修改
class CaseCompleteParams(BaseModel):
    url: Text
    detail: Text
    request_headers: Union[None, Dict, Text]
    request_data: Any
    method: Text
    expected: Union[None, Dict]
    extract: Union[None, Dict]
    status_code: int
    response_headers: Union[None, Dict, Text]
    response_data: Text
    response_time: float


"""allure 里面用例的执行状态"""


@dataclass
class TestMetrics:
    """ 用例执行状态 """
    passed: int
    failed: int
    broken: int
    skipped: int
    total: int
    pass_rate: float
    time: Text


if __name__ == '__main__':
    for x in Method:
        print(x.value)